from flask import current_app
from qiniu import Auth,put_file

class QiniuTool:
    def __init__(self):
        ak = current_app.config.get("AK")
        sk = current_app.config.get("SK")
        self.q = Auth(ak,sk)

    def uploadImg(self,locationpath,filename):
        bucket_name = current_app.config.get("BUCKET_NAME")
        token = self.q.upload_token(bucket_name,filename,3600)
        res = put_file(token,locationpath,filename,version='v2')
        if res[0]["key"] == filename:
            return filename
        else:
            return False